/*
 * Projekt: GMU 2013 - Canny hranovy detektor OpenCL/CUDA
 * Autori: Pavel Nevrala - xnevra00 (xnevra00@stud.fit.vutbr.cz)
 *         Martin Jurak - xjurak02 (xjurak02@stud.fit.vutbr.cz)
 */

#include "ParamController.h"

/*
 * Konstruktor	
 * Inicializace atributu
 */
ParamController::ParamController(void): thrLow(5), thrHigh(50), gaussDev(1.4f), gaussMaskSize(5), device(GPU)
{
}

/*
 * Destruktor
 */
ParamController::~ParamController(void)
{	
}

/*
 * Nacteni vstupnich parametru
 * @argc pocet parametru
 * @argv pole parametru
 */
void ParamController::parseArgs(int argc, char *argv[])
{	
	std::string arg;

	for(int i = 0; i < argc; i++){
		arg=argv[i];

		if(arg.compare("-in") == 0){
			if(i < argc-1)
				inImagePath.assign(argv[i+1]);
			else
				throw "\nERROR: Spatne zadane parametry!\n";
		}
		else if (arg.compare("-out") == 0){
			if(i < argc-1)
				outImagePath.assign(argv[i+1]);
			else
				throw "\nERROR: Spatne zadane parametry!\n";
		}
		else if (arg.compare("-thrL") == 0){
			if(i < argc-1)
				arg = argv[i+1];
			else
				throw "\nERROR: Spatne zadane parametry!\n";

			std::istringstream is(arg);			
			is >> thrLow;	

		}
		else if (arg.compare("-thrH") == 0){
			if(i < argc-1)
				arg = argv[i+1];
			else
				throw "\nERROR: Spatne zadane parametry!\n";

			std::istringstream is(arg);			
			is >> thrHigh;			
		}
		else if (arg.compare("-gSize") == 0){
			if(i < argc-1)
				arg = argv[i+1];
			else
				throw "\nERROR: Spatne zadane parametry!\n";

			std::istringstream is(arg);			
			is >> gaussMaskSize;
		}
		else if (arg.compare("-gDev") == 0){
			if(i < argc-1)
				arg = argv[i+1];
			else
				throw "\nERROR: Spatne zadane parametry!\n";

			std::istringstream is(arg);			
			is >> gaussDev;
		}
		else if (arg.compare("-cv") == 0){
			openCV = 1;
		}
		/*else if (arg.compare("-gpu") == 0){
			device = GPU;
		}
		else if (arg.compare("-cpu") == 0){
			device = CPU;
		}*/
	}

	if(inImagePath.empty()){
		throw "\nERROR: Neni zadana cesta k vstupnimu obrazu!\n";		
	}
	if(outImagePath.empty()){
		throw "\nERROR: Neni zadana cesta k vystupnimu obrazu!\n";		
	}

	if(gaussMaskSize%2 == 0 ){
		throw "\nERROR: Velikost Gaussovy masky musi byt licha!\n";		
	}

	if(gaussDev == 0 ){
		throw "\nERROR: Odchylka Gaussovy masky musi byt vetsi nez 0!\n";
	}

}